import { request } from "../../request/index.js"
Page({
  data: {
    goods: [],
    inpvalue: '',
    btnshow: true
  },
  onShow() {

  },
  handleInput(e) {
    const query = e.detail.value
    if (!query.trim()) {
      this.setData({
        goods: [],
        btnshow: true
      })
      return
    }
    clearTimeout(timeId)
    let timeId = setTimeout(() => {
      this.getgoods(query)
    }, 1000)
    this.setData({
      btnshow: false
    })
  },
  async getgoods(query) {
    const res = await request({ url: "goods/qsearch", data: { query } })
    const goods = res.data.message
    this.setData({
      goods
    })
  },
  handleclear() {
    this.setData({
      inpvalue: '',
      goods: [],
      btnshow: true

    })
  }
})